// pages/jifen/jifen.js
var app = getApp()
var ids = new Array();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    jifen:app.globalData.jifen,
    autoplay:true,
    indicatordots:true,
    imgUrls:[
      {image:"/Icon/Bell.png"},
      {image:"/Icon/Bell.png"},
      {image:"/Icon/Bell.png"},
      {image:"/Icon/Bell.png"},
    ],
    logos:[
      {image:"/Icon/Bell.png",title:"积分抽奖",id:1},
      {image:"/Icon/Bell.png",title:"积分历史",id:2},
    ],
    quick1:[
      {image:"/Icon/Bell.png",jifen:"100"},
      {image:"/Icon/Bell.png",jifen:"100"},
      {image:"/Icon/Bell.png",jifen:"100"},
      {image:"/Icon/Bell.png",jifen:"100"}
    ],
    quick2:[
      {image:"/Icon/Bell.png",jifen:"100"},
      {image:"/Icon/Bell.png",jifen:"100"},
      {image:"/Icon/Bell.png",jifen:"100"},
      {image:"/Icon/Bell.png",jifen:"100"}
    ],
    goods1:[
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:1},
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:2},
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:3},
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:4},
    
    ],
    goods2:[
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:5},
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:6},
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:7},
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:8},
    
    ],
    goods3:[
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:9},
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:10},
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:11},
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:12},
    
    ],
    goods4:[
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:13},
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:14},
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:15},
      {img:"/Icon/Bell.png",name:"123",instructions:"treq",jifen:"100",id:16},
    ],
    
  },
   
  btn:function (e) {
    var score = e.target.dataset.jifen;
    var that = this;
    var balance = this.data.jifen-score;
    

    console.log(e)
    if((balance)<0){
      wx.showToast({
      title: '您的积分不足！',
      icon: 'none',
      duration: 1500
    })
    }else{   
      that.setData({
        jifen:balance,
        
      })
      ids.push(e.target.dataset.id)
          // 设置缓存
          wx.setStorage({
            key: 'ids',
            data: ids ,
            success: function (res) {
            }
          })

      wx.showToast({
        title: '恭喜你兑换成功！',
        icon: 'none',
        duration: 1500})

    }
    //  console.log(ids);
  },
  
  choujiang:function(e){
    var id = e.target.dataset.id;
    // console.log(e)
    if(id==1){
      wx.navigateTo({
            url: '../choujiang/choujiang',
          })

    }else{
      wx.navigateTo({
        url: '../history/history',
      })
    }
   
  },

  rank:function(){
    wx.navigateTo({
      url: '../rank/rank',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that =this;
    wx.getSystemInfo( {
      success: function( res ) {
        // console.log(res)
          that.setData( {
              winWidth: res.windowWidth,
              winHeight: res.windowHeight
          });
      }

  });
  },
  swichNav: function( e ) {
    var that = this;
    if( this.data.currentTab === e.target.dataset.current ) {
        return false;
    } else {
        that.setData( {
            currentTab: e.target.dataset.current
        })
    }
},

bindChange: function( e ) {
    var that = this;
    that.setData( { currentTab: e.detail.current });

},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})